angular.module("app.controllers", ['ngSanitize', "testAdmob", "KuGuo"])
.controller("HomeCtrl", function($scope, $log, $cordovaGoogleAds, Groups) {
	console.log("home loaded");
	$scope.groups = Groups.all();

	/*
	$log.log($window.plugins.Admob);

	
	$log.log("Admob loaded");

	*/
	console.log("what happen channel not join yet");
	/*
	$cordovaGoogleAds.setOptions({
		adId : "ca-app-pub-3005563968785773/9375449045",
		position : 8,
		autoShow : true,
		isTesting : true
	});
	*/
	//$cordovaGoogleAds.showBanner();
	$log.log("test log");
	/*
	setTimeout(function(){
		//等待 所有插件 对象 构建完成 接着调用Admob 插件
		console.log("time out");
		$cordovaGoogleAds.setOptions({
		adId : "ca-app-pub-3005563968785773/9375449045",
		position : 8,
		autoShow : true,
		isTesting : true
	});
	}, 2000);
	*/
})
.controller("QuestionGroupCtrl", function($scope, $stateParams, Groups, Questions){
	$scope.group = Groups.get($stateParams.groupId);
	//Console.Log("Get Group is "+$scope.group);
	$scope.questions = Questions.all($stateParams.groupId);
})
.controller('QuestionCtrl', function($scope, $stateParams, Groups, Questions){
	$scope.group = Groups.get($stateParams.groupId);
	$scope.quest = Questions.get($stateParams.groupId, $stateParams.questId);
	//$scope.answer = $sce.trustAsHtml($scope.quest.answer);
	$scope.answer = $scope.quest.answer;
	$scope.detail = $scope.quest.detail;
})
.controller("AdMobCtrl", function($scope, $cordovaAdMobPro){


})
.run(function($rootScope, $admobSvc, $KuGuoSer){
		//setTimeout(function(){
			/*
			$admobSvc.setOptions({
				isTesting : false,
				autoShowBanner : true
			});
			*/

			console.log("rum admobSvc "+$admobSvc+ " "+$KuGuoSer);
			
			var temp = function(){
				setTimeout(temp, 2000);
				console.log("wait to call kuguo");
				$KuGuoSer.CreateBanner();
			}

			setTimeout(temp, 2000);
			/*
			$admobSvc.createBannerView({
				publisherId : "ca-app-pub-3005563968785773/9375449045",
				isTesting : false 
			});
			$rootScope.$on('admob:'+$admobSvc.events.onAdOpened, function onAdOpened(evt, e){
				console.log("adOpened :type of ad "+e.adType);
			});

			$admobSvc.showBannerAd();
			
			*/

	}

)

;
